package com.spzx.channel.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.channel.service.IndexService;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.domain.Category;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.dto.IndexHotData;
import com.spzx.product.api.domain.dto.ProductSkuDTO;
import com.spzx.product.api.domain.dto.SkuSearchDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping
@Tag(name = "首页模块")
public class IndexController extends BaseController {

    @Resource
    IndexService indexService;

    @Operation(summary = "查询首页热门数据")
    @GetMapping("index")
    public AjaxResult index() {
        IndexHotData indexHotData = indexService.getIndexData();
        return success(indexHotData);
    }

    @Operation(summary = "查询分类树数据")
    @GetMapping("category/tree")
    public AjaxResult listCatesTree(){
        List<Category> categories = indexService.listCatesTree();
        return success(categories);
    }

    @Operation(summary = "查询商品分类数据")
    @GetMapping("list/skuList/{pageNum}/{pageSize}")
    public TableDataInfo skuList(SkuSearchDTO skuSearchDTO){
        Page<ProductSku> page = indexService.skuList(skuSearchDTO);
        return getDataTable(page);
    }

    @Operation(summary = "查询商品详情数据")
    @GetMapping("item/{skuId}")
    public AjaxResult getSkuDetails(@PathVariable("skuId") Long skuId){
        ProductSkuDTO productSkuDTO = indexService.getSkuDetails(skuId);
        return success(productSkuDTO);
    }
}
